dim = size(G);
k = -1*(dim(1)-dim(2));
esq = 1;

for i = 1:(dim(2)-dim(1))-1
	if sum(G(i,1:k-1))==1
		if(not(G(i,i)==1))
			break;
		end
	else
		break;
	end
end

if i ~= (dim(2)-dim(1))-1
	esq = 0;
	for i = 1:(dim(2)-dim(1))-1
		if sum(G(i,k+1:dim(2)))==1
			if(not(G(i,i+k)==1))
				break;
			end
		else
			break;
		end
	end	
end

if i ~= (dim(2)-dim(1))-1
	printf('A matriz nao esta na forma sistematica!\n');
else
	if esq
		for i=1:dim(1)	
			H(:,i) = G(i,k:dim(2))';
		end
		for i=k:dim(2)
			H(i-k+1,i) = 1;
		end
	else
		for i=1:k
			H(i,i) = 1;
		end	
		for i=k+1:dim(2)
			H(:,i) = G(i-k,1:k)';
		end	
	end
end

dim = size(H);
dHmin = dim(2);
k = -1*(dim(1)-dim(2));


esq = 1;

for i = 1:(dim(2)-dim(1))-1
	if sum(H(i,1:k-1))==1
		if(not(H(i,i)==1))
			break;
		end
	else
		break;
	end
end

if i ~= (dim(2)-dim(1))-1
	esq = 0;
	for i = 1:(dim(2)-dim(1))-1
		if sum(H(i,k+1:dim(2)))==1
			if(not(H(i,i+k)==1))
				break;
			end
		else
			break;
		end
	end	
end

if i ~= (dim(2)-dim(1))-1
	printf('A matriz nao esta na forma sistematica!\n');
else
	if not(esq)
		dHmin = min(sum(H(:,1:k)))+1;
	else
		dHmin = min(sum(H(:,k+1:dim(2))))+1;
	end
end



% Faz a H transposta

Ht = H';

[k n] = size(G);

t = floor((dHmin-1)/2);

			
			
